package cn.ms.neural.common.log.impl;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;

import cn.ms.neural.common.log.ILog;
import cn.ms.neural.common.log.LogCollector.InternalLoggerFactory;

/**
 * Log4j2 Logger Factory
 * 
 * @author lry
 */
public class Log4j2LoggerFactory implements InternalLoggerFactory {

	public ILog getLogger(Class<?> clazz) {
		return new Log4j2Logger(clazz);
	}

	public ILog getLogger(String name) {
		return new Log4j2Logger(name);
	}
}

class Log4j2Logger extends ILog {
	
	private org.apache.logging.log4j.Logger log;

	Log4j2Logger(Class<?> clazz) {
		log = LogManager.getLogger(clazz);
	}

	Log4j2Logger(String name) {
		log = LogManager.getLogger(name);
	}

	public void debug(String format, Object... args) {
		log.log(Level.DEBUG, format, args);
	}

	public void info(String format, Object... args) {
		log.log(Level.INFO, format, args);
	}

	public void warn(String format, Object... args) {
		log.log(Level.WARN, format, args);
	}

	public void error(String format, Object... args) {
		log.log(Level.ERROR, format, args);
	}

	public void info(String message) {
		log.log(Level.INFO, message);
	}

	public void info(String message, Throwable t) {
		log.log(Level.INFO, message, t);
	}

	public void debug(String message) {
		log.log(Level.DEBUG, message);
	}

	public void debug(String message, Throwable t) {
		log.log(Level.DEBUG, message, t);
	}

	public void warn(String message) {
		log.log(Level.WARN, message);
	}

	public void warn(String message, Throwable t) {
		log.log(Level.WARN, message, t);
	}

	public void error(String message) {
		log.log(Level.ERROR, message);
	}

	public void error(String message, Throwable t) {
		log.log(Level.ERROR, message, t);
	}

	public void fatal(String message) {
		log.log(Level.FATAL, message);
	}

	public void fatal(String message, Throwable t) {
		log.log(Level.FATAL, message, t);
	}

	public boolean isDebugEnabled() {
		return log.isDebugEnabled();
	}

	public boolean isInfoEnabled() {
		return log.isInfoEnabled();
	}

	public boolean isWarnEnabled() {
		return log.isEnabled(Level.WARN);
	}

	public boolean isErrorEnabled() {
		return log.isEnabled(Level.ERROR);
	}

	public boolean isFatalEnabled() {
		return log.isEnabled(Level.FATAL);
	}

	public void trace(String message) {
		log.log(Level.TRACE, message);
	}

	public void trace(String message, Throwable t) {
		log.log(Level.TRACE, message, t);
	}

	public boolean isTraceEnabled() {
		return log.isTraceEnabled();
	}
}